#include <iostream>
#include <string>
#include <assert.h>
#include <websocketpp/uri.hpp>

void test_uri_valid(){
    websocketpp::uri uri("ws://localhost:9000/chat");

    assert(uri.get_valid());
    assert(!uri.get_secure());
    assert(uri.get_scheme() == "ws");
    assert(uri.get_host() == "localhost");
    assert(uri.get_port() == 9000);
    assert(uri.get_port_str() == "9000");
    assert(uri.get_resource() ==  "/chat");
    assert(uri.get_query().empty());
    assert(uri.str() == "ws://localhost:9000/chat");
    assert(uri.get_authority() == "localhost:9000");
    assert(uri.get_host_port() == "localhost:9000");

    websocketpp::uri uri1("ws://127.0.0.1/chat");
    assert(uri1.get_valid());
    assert(!uri.get_secure());
    assert(uri1.get_host() == "127.0.0.1");
    assert(uri1.get_port_str() == "80");
    assert(uri1.get_resource() ==  "/chat");

    websocketpp::uri uri2("wss://localhost/chat");
    assert(uri2.get_valid());
    assert(uri2.get_secure());
    assert(uri2.get_scheme() == "wss");
    assert(uri2.get_port() == 443);
    assert(uri2.get_resource() ==  "/chat");

    websocketpp::uri uri3("wss://localhost:9000");
    assert(uri3.get_port() == 9000);
    assert(uri3.get_resource() ==  "/");

    // Valid URI IPv6 Literal
    websocketpp::uri uri4("wss://[::1]:9000/chat");
    assert(uri4.get_host() == "::1");

    websocketpp::uri uri5("wss://thor-websocket.zaphoyd.net:88/");
    assert(uri5.get_host() == "thor-websocket.zaphoyd.net");

    // Invalid URI (port too long)
    websocketpp::uri uri6("wss://localhost:900000/chat");
    assert(!uri6.get_valid());

    websocketpp::uri uri7("http://localhost:9000/chat");
    assert(uri7.get_valid());


    websocketpp::uri uri8("wss://localhost:9000/chat/foo/bar");
    assert(uri8.get_resource() ==  "/chat/foo/bar");

    // Invalid URI includes uri fragment
    websocketpp::uri uri9("wss:/localhost:9002/chat#foo");
    assert(!uri9.get_valid());
}

int main(){
    test_uri_valid();
}
